package com.minhua.jijiehao2.utils;

import java.security.MessageDigest;


public class Md5Util {

    // private static final char[] hexDigits2 = { '0', '1', '2', '3', '4', '5',
    // '6', '7', '8', '9', 'a', 'b', 'c', 'd',
    // 'e', 'f' };
    private static final char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f'};

    public static String encryptGenerate(String data) {
        if (data == null || data.equals("")) {
            return null;
        } else {
            data = data.trim();
        }
        return encrypt(encrypt(encrypt(encrypt(data) + "msc50.com")));
    }

    public static String encrypt(String data) {
        try {
            byte[] bdata = data.getBytes("utf-8");
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(bdata);
            byte[] digests = md.digest();
            int len = digests.length;
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < len; i++) {
                byte byte0 = digests[i];
                sb.append(hexDigits[byte0 >>> 4 & 0xf]);
                sb.append(hexDigits[byte0 & 0xf]);
            }
            return sb.toString();
        } catch (Exception e) {
        }
        return null;
    }
}
